// pages/order-list/order-list.js
var util = require('../../utils/util.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderList:{},
    host: app.globalData.host,
    servicePhone: ''
  },
  onShow: function () {
    var sessionKey = app.globalData.userInfo.sessionKey;
    var host = app.globalData.host;
    var that = this;
    wx.request({
      url: host + '/order/list',
      data: {
        'session_key': sessionKey
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        let data = res.data;
        if (data.code == 2000) {
          that.setData({
            orderList: data.data[0],
            servicePhone: data.data[1]
          })
        } else {
          util.showModel('获取订单失败', data.msg)
        }
      }
    })
  },
  
  goodsDetail: function (e) {
    var goodsId = e.currentTarget.dataset.id;
    app.toGoodsDetail(goodsId);
  },

  orderDetail: function (e) {
    var orderId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../order-detail/order-detail?orderId=' + orderId
    })
  },
  contact: function() {
    wx.makePhoneCall({
      phoneNumber: this.data.servicePhone,
    })
  },

  refund: function(e) {
    var orderId = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;
    wx.navigateTo({
      url: '../refund/refund?orderId=' + orderId + '&status=' + status
    })
  },
})